# -*- coding: utf-8 -*-
# @Time : 2021/7/3 0:18
# @Author : 摘星星的小女孩
# @Email : wayne_lau@aliyun.com
# @File : page_ecshop_front_register.py
# @Project : ecshop
from selenium.webdriver.common.by import By


class PageEcshopFrontRegister():
    def __init__(self, driver):
        self.driver = driver
        # 元素定位符loc
        self.loc_ele_register_username = (By.ID, "username")
        self.loc_ele_register_email = (By.ID, "email")
        self.loc_ele_register_password = (By.ID, "password1")
        self.loc_ele_register_confirm_password = (By.NAME, "confirm_password")
        self.loc_ele_register_submit = (By.NAME, "Submit")
        self.loc_ele_register_assert = (By.XPATH, '//font[@id="ECS_MEMBERZONE"]/a[2]')

    # 注册
    def ele_register_username(self, username):  # 注册—用户名
        self.driver.find_element(*self.loc_ele_register_username).send_keys(username)

    def ele_register_email(self, email):  # 注册—邮箱
        self.driver.find_element(*self.loc_ele_register_email).send_keys(email)

    def ele_register_password(self, password):  # 注册—密码
        self.driver.find_element(*self.loc_ele_register_password).send_keys(password)

    def ele_register_confirm_password(self, confirm_password):  # 注册—确认密码
        self.driver.find_element(*self.loc_ele_register_confirm_password).send_keys(confirm_password)

    def ele_register_submit(self):  # 【会员注册】按钮
        self.driver.find_element(*self.loc_ele_register_submit).click()

    def ele_register_assert(self):
        actual = self.driver.find_element(*self.loc_ele_register_assert).text
        return actual

    def register(self, username, email, password, confirm_password):
        self.ele_register_username(username)
        self.ele_register_email(email)
        self.ele_register_password(password)
        self.ele_register_confirm_password(confirm_password)
        self.ele_register_submit()
        actual = self.ele_register_assert()
        return actual  #返回断言
